(function ($) {
	var timer;
	var sourceData;
	var currPage=0;//当前是第几题
	var currSlideIndex = 0;
	var pageCount = 0;
	var pageType = '';//practice随堂练习 classEndExam结课考核和去考核 analy解析  chapter章节练习
	var fromPage = ''
	var examineTimes;
	$.init();
	$.plusReady(function () {
	    baseSetup();
	})
	if (!mui.os.plus) {
		baseSetup()
	}
	
	function commitSureBtnTapped(){
		//结课考核
		var queDict = sourceData['ques']
		var arr = ['1','1','1','0','0','1','1','1','2','2']
		var score = 0;
		var isHasAsk = false;
		for (var i = 0; i < queDict.length;i++) {
			var ans = queDict[i]['ans'];
			var nurAns = queDict[i]['nurAns'];
			var oneScore = parseInt(queDict[i]['score'])
			switch (queDict[i]['type']) {
				case '单选题':
				case '多选题':
					if (ans == nurAns) {
						arr[i]='1'
						score += oneScore
					}else{
						arr[i]='0'
					}
					break;
				case '填空题':
					arr[i]='0'
					break;
				case '问答题':
					arr[i]='2'
					if (nurAns != '') {
						isHasAsk = true;
					}
					break;
			}
		}
		var data = {'score':score,'queItems':arr,'hasAsk':isHasAsk}
		var preWebview = plus.webview.getWebviewById(fromPage)
		if (pageType == 'practice' ) { //随堂练习或者课后作业
			preWebview.evalJS('refreshPracticeUI('+JSON.stringify(data)+')')
		}else if (pageType == 'classEndExam') {
			preWebview.evalJS('refreshExamineUI('+JSON.stringify(data)+')')
		}
		mui.toast('提交成功');
		$('#dhcBackdrop')[0].classList.remove('dhc-active');
		$('#commitPopo')[0].classList.remove('mui-active');
		mui.back();
	}
	
	// 题型--1单选,2多选,3填空,4问答
	function getExamineData(){
		var ques = [{'title':'男，62岁，患肺源性心脏病3年，近5日因受凉后痰多、黏稠、不易咳出，诉全身乏力，已卧床5日未解大便。该患者的首要问题是（）。',
			'type':'单选题','sub':'（2014年《专业实务》真题）','score':'10','ans':'A','nurAns':'',
			'options':[{'title':'便秘','op':'A'},{'title':'活动无耐力','op':'B'},{'title':'语言沟通障碍','op':'C'},{'title':'清理呼吸道','op':'D'},{'title':'皮肤完整性受损','op':'E'},]},
		{'title':'发挥药效最快的给药途径是：','type':'单选题','sub':'','score':'10','ans':'D','nurAns':'',
			'options':[{'title':'口服','op':'A'},{'title':'皮下注射','op':'B'},{'title':'吸入疗法','op':'C'},{'title':'静脉注射','op':'D'}]},
		{'title':'应远离明火处保存的药物是：','type':'多选题','sub':'','score':'10','ans':'CD','nurAns':'',
			'options':[{'title':'抗毒血清','op':'A'},{'title':'胎盘球蛋白','op':'B'},{'title':'乙醚','op':'C'},{'title':'酒精','op':'D'}]},
		{'title':'皮内注射选择前臂掌侧下段是因为该处：','type':'单选题','sub':'','score':'10','ans':'A','nurAns':'',
			'options':[{'title':'皮肤薄、 色浅','op':'A'},{'title':'无大血管','op':'B'},{'title':'离大神经远','op':'C'},{'title':'操作较便','op':'D'}]},
		{'title':'剧毒药和麻醉药的最主要保管原则是：','type':'单选题','sub':'','score':'10','ans':'B','nurAns':'',
			'options':[{'title':'药品用中外文对照','op':'A'},{'title':'加锁并认真交班','op':'B'},{'title':'装密封瓶内保存','op':'C'},{'title':'与内服药分开放置','op':'D'}]},
		{'title':'护理十四项核心制度包括哪些？','type':'问答题','sub':'（人工阅卷）','score':'30','ans':'','nurAns':''},
		{'title':'输卵管由内侧向外侧分为四个部分，即<div class="blank">（1）</div>、<div class="blank">（2）</div>、<div class="blank">（3）</div>、<div class="blank">（4）</div>。','type':'填空题','sub':'','score':'10','ans':'D','nurAns':'',
			'options':[{'title':'子宫部','op':'（1）'},{'title':'峡部','op':'（2）'},{'title':'壶腹部','op':'（3）'},{'title':'大漏斗部','op':'（4）'}]}];
		var dict = {'type':'','ques':ques,'time':'30:00'}
		if (document.body.getAttribute('class').indexOf('notTiming') == -1) { //题目解析
			$('#reduceTime')[0].innerHTML = dict['time']
			timer = setTimeout(timeReduce, 1000);
		}
		
		sourceData = dict;
		pageCount = ques.length
		
		for(var i = 0; i < 3;i++){
			if(i < pageCount){
				updateOneQuesUI(i,i);
			}else{
				var dom = $('#'+i)[0]
				if(dom){
					$('#loop')[0].removeChild(dom)
				}
				continue
			}
		}
		currSlideIndex = 0;
		currPage = 1;
		$('#currPage')[0].innerHTML = currPage;
		$('#pageCount')[0].innerHTML = pageCount;
		updateCommitPopoUI();
	}
	function updateCommitPopoUI(){
		var commitScroll = $('#commitScroll')[0]
		var html = ''
		for (var i = 1;i <= pageCount;i++) {
			html += '<div id="item-'+(i-1)+'" class="oneItem notAns">'+i+'</div>'
		}
		commitScroll.innerHTML = html;
	}
	
	function updateOneQuesUI(index,domId){
		var queDict = sourceData['ques'][index]
		var type = queDict['type'];
		var title = queDict['title'];
		var sub = queDict['sub'];
		var score = queDict['score'];
		var html = '<div class="examTitle">'+(index+1)+'、<span class="examType">【'+type+'】</span>'+title
		if(sub != '' && type != '问答题'){
			html += '<span class="subText">'+sub+'</span>'
		}else if(sub != '' && type == '问答题'){
			html += '<span class="askText">'+sub+'</span>'
		}
		html += '<span class="scoreText">（'+score+'分）</span></div>';
		var muiScroll = $('#'+domId)[0].querySelector('.mui-scroll')
		muiScroll.innerHTML = html
		switch (type) {
			case '单选题':
				createRadioUI(queDict,muiScroll,index);
				break;
			case '多选题':
				createCheckboxUI(queDict,muiScroll,index);
				break;
			case '填空题':
				createMultiBlankUI(queDict,muiScroll,index);
				break;
			case '问答题':
				createAskUI(queDict,muiScroll,index);
				break;
		}
	}
	
	// 单选
	function createRadioUI(queDict,scrollDom,index){
		scrollDom.classList.remove('analysisMode')
		var option = queDict['options']
		var optionsArea = document.createElement('div');
		optionsArea.id = 'ques-'+index
		optionsArea.classList.add('optionsArea');
		scrollDom.appendChild(optionsArea);
		
		var html = ''
		var nurAns = queDict['nurAns']
		for(var i= 0; i < option.length;i++){
			var one = option[i];
			var op = one['op']
			var activeClass=''
			if(nurAns!="" && op == nurAns){
				 activeClass='dhc-active'
			}
			html += '<div class="option '+activeClass+'">'+
				'<div class="opName nurfont" data-op="'+one['op']+'">'+one['op']+'</div>'+
				'<div class="opTitle">'+one['title']+'</div></div>'
		}
		optionsArea.innerHTML = html;
		if (pageType != 'analy' && (pageType == 'chapter' && queDict['nurAns']=="")) {
			var options = optionsArea.querySelectorAll('.option');
			for (var i = 0; i < options.length;i++) {
				options[i].addEventListener('tap',radioOptionTapped);
			}
			return
		}
		//解析部分
		radioOptionAddAnaly(optionsArea,scrollDom);
		
	}
	
	function radioOptionAddAnaly(optionsArea,scrollDom){
		var error = optionsArea.querySelector('.opName[data-op="A"]');
		error.innerHTML = ''
		error.classList.add('nur-error')
		var correct = optionsArea.querySelector('.opName[data-op="D"]');
		correct.innerHTML = ''
		correct.classList.add('nur-correct')
		
		scrollDom.classList.add('analysisMode')
		var analysisArea = document.createElement('div');
		analysisArea.classList.add('analysisArea');
		scrollDom.appendChild(analysisArea);
		var analysisText = '根据患者的诊断与临床表现：受凉后痰多、黏稠、不易咳出可看出保持患者的呼吸道通畅是目前迫切需要解决的问题。';
		html = '<div class="ansCompare">正确答案：<span class="correctAns">D</span>&nbsp;&nbsp;'+
				'您的答案：<span class="yourAns">A</span></div>'+
			'<div class="seperateBar"></div>'+
			'<div class="analysisText">解析：<br/>'+analysisText+'</div>'+
			'<div class="seperateLine"></div><div class="errorRate">本系统作答 875 次，错误率23.58%</div>'
		analysisArea.innerHTML = html
	}
	
	function radioOptionTapped(){
		var parentNode = this.parentNode;
		var index = parseInt(parentNode.id.split('-')[1])
		var thisData = sourceData['ques'][index];
		if (pageType != 'chapter') {
			var oldActive = parentNode.querySelector('.dhc-active');
			if (oldActive) {
				oldActive.classList.remove('dhc-active');
			}
			this.classList.add('dhc-active');
		}
		thisData['nurAns'] = this.querySelector('.opName').innerText;
		$('#item-'+index)[0].classList.remove('notAns')
		
		if (pageType == 'chapter') { //章节练习
			var optionsArea = parentNode
			var scrollDom = optionsArea.parentNode
			var options = optionsArea.querySelectorAll('.option');
			mui.each(options,function(index,item){
				item.removeEventListener('tap',radioOptionTapped)
			})
			if (scrollDom.getAttribute('class').indexOf('analysisMode')!= -1) {
				return;
			}
			radioOptionAddAnaly(optionsArea,scrollDom);
			return
		}
		//滚动到下一页
		gotoNextPage(100);
		
	}
	// 多选
	function createCheckboxUI(queDict,scrollDom,index){
		scrollDom.classList.remove('analysisMode')
		var option = queDict['options']
		var optionsArea = document.createElement('div');
		optionsArea.id = 'ques-'+index
		optionsArea.classList.add('optionsArea');
		scrollDom.appendChild(optionsArea);
		
		var html = ''
		var nurAns = queDict['nurAns']
		for(var i= 0; i< option.length;i++){
			var one = option[i];
			var op = one['op']
			var activeClass=''
			if(nurAns!="" && op != "" && nurAns.indexOf(op) != -1){
				 activeClass='dhc-active'
			}
			html += '<div class="option '+activeClass+'">'+
				'<div class="opName nurfont" data-op="'+one['op']+'">'+one['op']+'</div>'+
				'<div class="opTitle">'+one['title']+'</div></div>'
		}
		optionsArea.innerHTML = html;
		//确认答案
		var sureAnsBtn = document.createElement('div');
		sureAnsBtn.id = 'sure-'+index
		sureAnsBtn.classList.add('sureAnsBtn');
		sureAnsBtn.innerText = '确认答案'
		sureAnsBtn.addEventListener('tap',checkboxSureAnsBtnTapped)
		scrollDom.appendChild(sureAnsBtn);
		// 点击方法
		if (pageType != 'analy' && (pageType == 'chapter' && queDict['nurAns']=="")) {
			var options = optionsArea.querySelectorAll('.option');
			for (var i = 0; i < options.length;i++) {
				options[i].addEventListener('tap',checkboxOptionTapped);
			}
			return
		}
		//解析部分
		checkboxOptionAddAnaly(optionsArea,scrollDom);
		
	}
	
	function checkboxOptionAddAnaly(optionsArea,scrollDom){
		var correct = optionsArea.querySelector('.opName[data-op="A"]');
		correct.innerHTML = ''
		correct.classList.add('nur-correct')
		var correct = optionsArea.querySelector('.opName[data-op="C"]');
		correct.innerHTML = ''
		correct.classList.add('nur-correct')
		
		var error = optionsArea.querySelector('.opName[data-op="D"]');
		error.innerHTML = ''
		error.classList.add('nur-error')
		
		scrollDom.classList.add('analysisMode')
		var analysisArea = document.createElement('div');
		analysisArea.classList.add('analysisArea');
		scrollDom.appendChild(analysisArea);
		var analysisText = '根据患者的诊断与临床表现：受凉后痰多、黏稠、不易咳出可看出保持患者的呼吸道通畅是目前迫切需要解决的问题。';
		html = '<div class="ansCompare">正确答案：<span class="correctAns">AC</span>&nbsp;&nbsp;'+
				'您的答案：<span class="yourAns">AD</span></div>'+
			'<div class="seperateBar"></div>'+
			'<div class="analysisText">解析：<br/>'+analysisText+'</div>'+
			'<div class="seperateLine"></div><div class="errorRate">本系统作答 875 次，错误率23.58%</div>'
		analysisArea.innerHTML = html
	}
	function checkboxOptionTapped(){
		if (pageType == 'chapter') { //章节练习
			var optionsArea = this.parentNode
			var scrollDom = optionsArea.parentNode
			if (scrollDom.getAttribute('class').indexOf('analysisMode')!= -1) {
				return;
			}
		}
		if (this.getAttribute('class').indexOf('dhc-active') != -1) {
			this.classList.remove('dhc-active');
		}else{
			this.classList.add('dhc-active');
		}
	}
	function checkboxSureAnsBtnTapped(){
		var index = parseInt(this.id.split('-')[1])
		var options = this.parentNode.querySelectorAll('.option.dhc-active .opName');
		var nurAns = ''
		for (var i = 0; i < options.length;i++) {
			nurAns += options[i].innerText;
		}
		
		sourceData['ques'][index]['nurAns'] = nurAns;
		if (nurAns == '') {
			$('#item-'+index)[0].classList.add('notAns')
			mui.toast('请先选择您的答案')
			return
		}else{
			$('#item-'+index)[0].classList.remove('notAns')
		}
		if (pageType == 'chapter') { //章节练习
			
			var scrollDom = this.parentNode
			var optionsArea = scrollDom.querySelector('.optionsArea')
			var options = optionsArea.querySelectorAll('.option');
			mui.each(options,function(index,item){
				item.removeEventListener('tap',radioOptionTapped)
			})
			if (scrollDom.getAttribute('class').indexOf('analysisMode')!= -1) {
				return;
			}
			checkboxOptionAddAnaly(optionsArea,scrollDom);
			return
		}
		//滚动到下一个
		gotoNextPage();
	}
	
	// 填空
	function createMultiBlankUI(queDict,scrollDom,index){
		scrollDom.classList.remove('analysisMode')
		var option = queDict['options']
		var optionsArea = document.createElement('div');
		optionsArea.id = 'ques-'+index
		optionsArea.classList.add('optionsArea');
		scrollDom.appendChild(optionsArea);
		
		var html = ''
		var nurAns = queDict['nurAns']
		if (nurAns == '') {
			nurAns = {}
		}
		for(var i= 0; i< option.length;i++){
			var one = option[i];
			var op = one['op']
			var value = nurAns[op] == undefined?"":nurAns[op];
			html += '<div class="option"><div class="fillName">'+one['op']+'</div><input type="text" value="'+value+'" /></div>'
		}
		optionsArea.innerHTML = html;
		//确认答案
		var sureAnsBtn = document.createElement('div');
		sureAnsBtn.id = 'sure-'+index
		sureAnsBtn.classList.add('sureAnsBtn');
		sureAnsBtn.innerText = '确认答案'
		sureAnsBtn.addEventListener('tap',blankSureAnsBtnTapped)
		scrollDom.appendChild(sureAnsBtn);
		
		if (pageType != 'analy' && (pageType == 'chapter' && queDict['nurAns']=="")) {
			return;
		}
		// 解析
		blankAddAnaly(optionsArea,scrollDom,queDict)
		
	}
	
	function blankAddAnaly(optionsArea,scrollDom,queDict){
		var option = queDict['options']
		var nurAns = queDict['nurAns']
		optionsArea.style.display = 'none';
		scrollDom.classList.add('analysisMode')
		var analysisArea = document.createElement('div');
		analysisArea.classList.add('analysisArea');
		scrollDom.appendChild(analysisArea);
		html = ''
		for(var i= 0; i< option.length;i++){
			var one = option[i];
			var op = one['op']
			var value = nurAns[op] == undefined?"":nurAns[op];
			html += '<div class="option"><div class="fillName">'+one['op']+'</div>'+
				'<div class="fillText">'+one['title']+'</div>';
			if (i == 3) {
				html += '<div class="nurfont nur-error"></div></div>'
			}else{
				html += '<div class="nurfont nur-correct"></div></div>'
			}
				
		}
		var ansText = '输卵管由内侧向外侧分为四个部分，即<div>子宫部</div>、<div>峡部</div>、<div>壶腹部</div>、<div>漏斗部</div>。'
		var analysisText = '根据患者的诊断与临床表现：受凉后痰多、黏稠、不易咳出可看出保持患者的呼吸道通畅是目前迫切需要解决的问题。';
		html += '<div class="correctFillText">正确答案：<br/>'+ansText+'</div>'+
			'<div class="seperateBar"></div>'+
			'<div class="analysisText">解析：<br/>'+analysisText+'</div>'+
			'<div class="seperateLine"></div><div class="errorRate">本系统作答 875 次，错误率23.58%</div>'
		analysisArea.innerHTML = html
	}
	
	function blankSureAnsBtnTapped(){
		var index = parseInt(this.id.split('-')[1])
		var options = this.parentNode.querySelectorAll('.option');
		var nurAns = {}
		var isEmpty = true;
		for (var i = 0; i < options.length;i++) {
			var fillName = options[i].querySelector('.fillName').innerText;
			var value = options[i].querySelector('input').value;
			nurAns[fillName] = value
			if (value != '') {
				isEmpty = false
			}
		}
		sourceData['ques'][index]['nurAns'] = nurAns;
		if (isEmpty) {
			$('#item-'+index)[0].classList.add('notAns')
			mui.toast('请先填写您的答案')
			return
		}else{
			$('#item-'+index)[0].classList.remove('notAns')
		}
		if (pageType == 'chapter') { //章节练习
			
			var scrollDom = this.parentNode
			var optionsArea = scrollDom.querySelector('.optionsArea')
			var options = optionsArea.querySelectorAll('.option');
			mui.each(options,function(index,item){
				item.removeEventListener('tap',radioOptionTapped)
			})
			if (scrollDom.getAttribute('class').indexOf('analysisMode')!= -1) {
				return;
			}
			blankAddAnaly(optionsArea,scrollDom,sourceData['ques'][index]);
			return
		}
		//滚动到下一个
		gotoNextPage();
	}
	
	// 问答
	function createAskUI(queDict,scrollDom,index){
		scrollDom.classList.remove('analysisMode')
		var option = queDict['options']
		var optionsArea = document.createElement('div');
		optionsArea.id = 'ques-'+index
		optionsArea.classList.add('optionsArea');
		scrollDom.appendChild(optionsArea);
		optionsArea.innerHTML = '<textarea></textarea>';
		optionsArea.querySelector('textarea').value = queDict['nurAns']
		//确认答案
		var sureAnsBtn = document.createElement('div');
		sureAnsBtn.id = 'sure-'+index
		sureAnsBtn.classList.add('sureAnsBtn');
		sureAnsBtn.innerText = '确认答案'
		sureAnsBtn.addEventListener('tap',askSureAnsBtnTapped)
		scrollDom.appendChild(sureAnsBtn);
		
		if (pageType != 'analy') {
			return
		}
		//解析部分
		scrollDom.classList.add('analysisMode')
		var analysisArea = document.createElement('div');
		analysisArea.classList.add('analysisArea');
		scrollDom.appendChild(analysisArea);
		var yourText = '1.护理质量管理制度；2.病房管理制度；3.抢救工作制度；4.分级护理制度；5.护理交接班制度；6.查对制度；7.给药制度；8.护理查房制度；9.患者健康教育制度；10.护理会诊制度；11.护理安全管理制度；12.患者身份识别制度；13.护理不良事件报告制度；14.病房一般消毒隔离管理制度。';
		var ansText = '1.护理质量管理制度；2.病房管理制度；3.抢救工作制度；4.分级护理制度；5.护理交接班制度；6.查对制度；7.给药制度；8.护理查房制度；9.患者健康教育制度；10.护理会诊制度；11.护理安全管理制度；12.患者身份识别制度；13.护理不良事件报告制度；14.病房一般消毒隔离管理制度。'
		var analysisText = '根据患者的诊断与临床表现：受凉后痰多、黏稠、不易咳出可看出保持患者的呼吸道通畅是目前迫切需要解决的问题。';
		html = '<div class="yourAskText">'+yourText+'</div>'+
			'<div class="correctAskText">参考答案：<br/>'+ansText+'</div>'+
			'<div class="seperateBar"></div>'+
			'<div class="analysisText">解析：<br/>'+analysisText+'</div>'+
			'<div class="textTip">批注：</div>'+
			'<div class="notes">回答的非常正确，抓住了重点。</div>'+
			'<div class="textTip">分数：<div class="askScore">10</div>分</div>'
		analysisArea.innerHTML = html
	}
	function askSureAnsBtnTapped(){
		var index = parseInt(this.id.split('-')[1])
		var textarea = this.parentNode.querySelector('textarea');
		var nurAns = textarea.value;
		sourceData['ques'][index]['nurAns'] = nurAns;
		if (nurAns == '') {
			$('#item-'+index)[0].classList.add('notAns')
		}else{
			$('#item-'+index)[0].classList.remove('notAns')
		}
		//滚动到下一个
		gotoNextPage();
	}
	// delayTime延迟时间
	function gotoNextPage(delayTime){
		if (currPage == pageCount) {
			mui.toast('已经是最后一题了')
			return
		}
		if (!delayTime) {
			delayTime = 0
		}
		setTimeout(function(){
			$("#slider").slider().nextItem();
		},delayTime)
		
	}
	
	function refreshSliderItemUI(index){
		var direction = 0
		if (currSlideIndex == 0 && index == 2) { //右滑
			direction = -1
		}else if (currSlideIndex == 2 && index == 0) { //左滑
			direction = 1
		}else if (currSlideIndex > index) { //右滑
			direction = -1
		}else if (currSlideIndex < index) { //左滑
			direction = 1
		}
		if (direction == 0) {
			return
		}
		if (currPage + direction > pageCount || currPage + direction < 1) {
			return
		}
		currPage += direction
		$('#currPage')[0].innerHTML = currPage; //当前页
		if (!$('#last')[0] && pageCount > 3 && currPage == 3 && direction == 1) { //左滑时到第三页打开轮播功能
			turnOnTurnOffSlider(1,2)
			//第一页变成下一题
			updateOneQuesUI(currPage,0);
			$('#first')[0].innerHTML = $('#0')[0].innerHTML
			$('#last')[0].innerHTML = $('#2')[0].innerHTML
			currSlideIndex = 2
		}else if($('#last')[0] && pageCount > 3 && currPage == 1 && direction == -1){ //右滑时到第一页关闭轮播功能
			turnOnTurnOffSlider(0)
			updateOneQuesUI(0,0);
			//$('#0')[0].innerHTML = $('#'+index)[0].innerHTML
			$("#slider").slider().gotoItem(0,0);
			updateOneQuesUI(1,1);
			updateOneQuesUI(2,2);
			currSlideIndex = 0
			//重置item
		}else if($('#last')[0] && pageCount > 3 && currPage == pageCount && direction == 1){//左滑时到第最后页关闭轮播功能
			turnOnTurnOffSlider(0)
			updateOneQuesUI(pageCount-1,2);
			//$('#2')[0].innerHTML = $('#'+index)[0].innerHTML
			$("#slider").slider().gotoItem(2,0);
			updateOneQuesUI(pageCount-2,1);
			updateOneQuesUI(pageCount-3,0);
			currSlideIndex = 2
		}else if(!$('#last')[0] && pageCount > 3 && currPage == pageCount-2 && direction == -1){ //右滑时到第倒数第三页打开轮播功能
			turnOnTurnOffSlider(1,0)
			//最后一页变成前一题
			updateOneQuesUI(currPage-2,2);
			$('#first')[0].innerHTML = $('#0')[0].innerHTML
			$('#last')[0].innerHTML = $('#2')[0].innerHTML
			currSlideIndex = 0
		}else{
			currSlideIndex = index;
			if (direction == 1) { //左滑
				if (currPage < 3) {
					return
				}
				if (index == 0) {
					updateOneQuesUI(currPage,1);
				}else if (index == 1) {
					updateOneQuesUI(currPage,2);
					$('#last')[0].innerHTML = $('#2')[0].innerHTML
				}else{
					updateOneQuesUI(currPage,0);
					$('#first')[0].innerHTML = $('#0')[0].innerHTML
				}
			}else{ //右滑
				if (currPage > pageCount - 2) {
					return
				}
				if (index == 0) {
					updateOneQuesUI(currPage-2,2);
					$('#last')[0].innerHTML = $('#2')[0].innerHTML
				}else if (index == 1) {
					updateOneQuesUI(currPage-2,0);
					$('#first')[0].innerHTML = $('#0')[0].innerHTML
					
				}else{
					updateOneQuesUI(currPage-2,1);
				}
			}
		}
	}
	
	function turnOnTurnOffSlider(flag,index){
		var loop = $('#loop')[0]
		var last = $('#last')[0]
		var first = $('#first')[0]
		if(flag == 1 && !last){
			var last = document.createElement('div');
			last.id = 'last';
			last.setAttribute('class','mui-slider-item mui-slider-item-duplicate')
			last.innerHTML = '<div class="mui-scroll-wrapper"><div class="mui-scroll"></div></div>'
			var first = document.createElement('div');
			first.id = 'first';
			first.setAttribute('class','mui-slider-item mui-slider-item-duplicate')
			first.innerHTML = '<div class="mui-scroll-wrapper"><div class="mui-scroll"></div></div>'
			loop.insertBefore(last,$('#0')[0])
			loop.appendChild(first)
			loop.classList.add('mui-slider-loop');
			$("#slider").slider({
				interval: 0
			}).gotoItem(index,0);
			mui('#slider').slider().refresh();
		}else if(flag != 1 && last){
			loop.classList.remove('mui-slider-loop')
			loop.removeChild(last);
			loop.removeChild(first)
			mui('#slider').slider().refresh();
		}
	}
	
	function sliderSlideAction(){
		var index = event.detail.slideNumber;
		refreshSliderItemUI(index)
	}
	
	function timeReduce() {
		var timeBtn =  $('#reduceTime')[0];
		var timeStr = timeBtn.innerText;
		if(timeStr == "00:00") {
			var commitPopo = $('#commitPopo')[0];
			commitPopo.classList.add('forceCommit');
			if (commitPopo.getAttribute('class').indexOf('mui-active') == -1) {
				$('#dhcBackdrop')[0].classList.add('dhc-active');
				commitPopo.classList.add('mui-active');
			}
		} else {
			var newStr = hourMinuteSecondReduce(timeStr);
			timeBtn.innerText = newStr;
			timer = setTimeout(timeReduce, 1000);
		}
	}
	function baseSetup(){
		$('.mui-scroll-wrapper').scroll({
			bounce: true,
			indicators: false, //是否显示滚动条
		});
		if (mui.os.plus) {
			var self = plus.webview.currentWebview()
			sourceData = self.sourceData;
			pageType = self.pageType;
			fromPage = self.fromPage;
		}
		
		if (fromPage == 'toTrain' && pageType == 'classEndExam') {
			$('.mui-title')[0].innerText = '结课考核'
		}else if (fromPage == 'toExamine') {
			$('.mui-title')[0].innerText = '在线考核'
		}else if (fromPage == 'examChapter' || fromPage == 'examError') {
			if (fromPage == 'examChapter') {
				$('.mui-title')[0].innerText = '章节练习'
			}else{
				$('.mui-title')[0].innerText = '错题本'
			}
			$('.btnArea')[0].classList.add('chapterMode')
			$('.mui-content .btnArea .chapterTitle')[0].addEventListener('tap',function(){
				if ($('.btnArea')[0].getAttribute('class').indexOf('dhc-active') != -1) {
					$('.btnArea')[0].classList.remove('dhc-active')
					$('#dhcBackdrop')[0].classList.remove('dhc-active')
				}else{
					$('.btnArea')[0].classList.add('dhc-active')
					$('#dhcBackdrop')[0].classList.add('dhc-active')
				}
			})
		}
		 
		// 底部的结束按钮
		$('.mui-content .btnArea .finishBtn')[0].addEventListener('tap',function(){
			mui.back();
		})
		// 底部的交卷按钮
		$('.mui-content .btnArea .baseBtn')[0].addEventListener('tap',function(){
			$('#dhcBackdrop')[0].classList.add('dhc-active');
			$('#commitPopo')[0].classList.add('mui-active');
		})
		// 交卷弹框中的取消按钮
		$('.commitPopo .cancenBtn')[0].addEventListener('tap',function(){
			$('#dhcBackdrop')[0].classList.remove('dhc-active');
			$('#commitPopo')[0].classList.remove('mui-active');
		})
		// 交卷弹框中的确定按钮
		$('.commitPopo .sureBtn')[0].addEventListener('tap',commitSureBtnTapped)
		if (pageType != 'practice' && pageType != 'classEndExam') {
			document.body.classList.add('notTiming')
		}
		// 监听滚动
		var slider = document.getElementById('slider');
		slider.addEventListener('slide', sliderSlideAction);
		getExamineData()
	}
	
})(mui);